<template>
  <div class="login-container">
    <!-- 装饰背景 -->
    <div class="decorative-shapes">
      <div class="shape shape-1"></div>
      <div class="shape shape-2"></div>
      <div class="shape shape-3"></div>
    </div>
    
    <div class="login-content">
      <!-- 左侧：品牌展示 -->
      <div class="brand-section animate-fade-in-up">
        <div class="brand-icon">
          <svg viewBox="0 0 200 200" class="w-24 h-24 mb-6">
            <defs>
              <linearGradient id="brandGradient" x1="0%" y1="0%" x2="100%" y2="100%">
                <stop offset="0%" style="stop-color:#ec4899;stop-opacity:1" />
                <stop offset="50%" style="stop-color:#d946ef;stop-opacity:1" />
                <stop offset="100%" style="stop-color:#8b5cf6;stop-opacity:1" />
              </linearGradient>
            </defs>
            <path d="M100 20 L180 60 L180 140 L100 180 L20 140 L20 60 Z" 
                  fill="url(#brandGradient)" stroke="white" stroke-width="2"/>
            <circle cx="100" cy="80" r="15" fill="white"/>
            <rect x="85" y="100" width="30" height="60" rx="5" fill="white"/>
          </svg>
        </div>
        <h1 class="brand-title gradient-text">智能试衣间</h1>
        <p class="brand-subtitle">AI Virtual Fitting Room</p>
        <p class="brand-description">用科技改变试衣体验<br/>让时尚触手可及</p>
        <div class="feature-list">
          <div class="feature-item">
            <span class="feature-icon">✨</span>
            <span>AI智能试穿</span>
          </div>
          <div class="feature-item">
            <span class="feature-icon">🎨</span>
            <span>实时效果预览</span>
          </div>
          <div class="feature-item">
            <span class="feature-icon">📸</span>
            <span>一键保存分享</span>
          </div>
        </div>
      </div>
      
      <!-- 右侧：登录表单 -->
      <div class="form-section animate-fade-in-up">
        <el-card class="login-card glass-effect">
          <div class="form-header">
            <h2 class="form-title">欢迎回来</h2>
            <p class="form-subtitle">登录您的账号，开始试衣之旅</p>
          </div>
          
          <el-form :model="form" :rules="rules" ref="formRef" class="login-form">
            <el-form-item prop="username">
              <div class="input-label">
                <el-icon><User /></el-icon>
                <span>用户名</span>
              </div>
              <el-input 
                v-model="form.username" 
                placeholder="请输入用户名" 
                size="large"
                clearable
              />
            </el-form-item>
            
            <el-form-item prop="password">
              <div class="input-label">
                <el-icon><Lock /></el-icon>
                <span>密码</span>
              </div>
              <el-input 
                v-model="form.password" 
                type="password" 
                placeholder="请输入密码"
                show-password
                size="large"
                @keyup.enter="handleLogin"
              />
            </el-form-item>
            
            <el-form-item>
              <el-button 
                type="primary" 
                size="large"
                class="login-button"
                :loading="loading" 
                @click="handleLogin"
              >
                <span v-if="!loading">立即登录</span>
                <span v-else>登录中...</span>
              </el-button>
            </el-form-item>
            
            <div class="form-footer">
              <span class="footer-text">还没有账号？</span>
              <el-link 
                type="primary" 
                :underline="false"
                class="register-link"
                @click="router.push('/register')"
              >
                立即注册
              </el-link>
            </div>
          </el-form>
        </el-card>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { User, Lock } from '@element-plus/icons-vue'
import { useAuthStore } from '@/stores/auth'

// @generatedBy AI-CodeGen
// @lastModified 2025-10-27

const router = useRouter()
const authStore = useAuthStore()
const formRef = ref(null)
const loading = ref(false)

const form = ref({
  username: '',
  password: ''
})

const rules = {
  username: [
    { required: true, message: '请输入用户名', trigger: 'blur' }
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' }
  ]
}

const handleLogin = async () => {
  if (!formRef.value) return
  
  await formRef.value.validate(async (valid) => {
    if (valid) {
      loading.value = true
      try {
        await authStore.login(form.value.username, form.value.password)
        ElMessage.success('登录成功！欢迎回来 ✨')
        router.push('/tryon')
      } catch (error) {
        ElMessage.error(error.response?.data?.message || '登录失败，请检查用户名和密码')
      } finally {
        loading.value = false
      }
    }
  })
}
</script>

<style scoped>
.login-container {
  position: relative;
  min-height: 100vh;
  background: linear-gradient(135deg, #1e1b4b 0%, #581c87 50%, #831843 100%);
  overflow: hidden;
}

/* 装饰性背景形状 */
.decorative-shapes {
  position: absolute;
  width: 100%;
  height: 100%;
  overflow: hidden;
  opacity: 0.1;
}

.shape {
  position: absolute;
  border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%;
  background: linear-gradient(135deg, #ec4899, #d946ef, #8b5cf6);
  animation: float 6s ease-in-out infinite;
}

.shape-1 {
  width: 300px;
  height: 300px;
  top: 10%;
  left: 10%;
  animation-delay: 0s;
}

.shape-2 {
  width: 400px;
  height: 400px;
  bottom: 10%;
  right: 10%;
  animation-delay: 2s;
}

.shape-3 {
  width: 250px;
  height: 250px;
  top: 50%;
  left: 50%;
  animation-delay: 4s;
}

/* 主内容区域 */
.login-content {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4rem;
  align-items: center;
  min-height: 100vh;
  padding: 2rem 4rem;
  max-width: 1400px;
  margin: 0 auto;
}

/* 左侧品牌区域 */
.brand-section {
  color: white;
  text-align: center;
  animation-delay: 0.2s;
}

.brand-icon {
  display: flex;
  justify-content: center;
  margin-bottom: 2rem;
}

.brand-icon svg {
  filter: drop-shadow(0 10px 30px rgba(217, 70, 239, 0.4));
  animation: float 3s ease-in-out infinite;
}

.brand-title {
  font-size: 3.5rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}

.brand-subtitle {
  font-size: 1.25rem;
  color: rgba(255, 255, 255, 0.8);
  font-weight: 300;
  margin-bottom: 1.5rem;
  letter-spacing: 0.1em;
}

.brand-description {
  font-size: 1.125rem;
  line-height: 1.8;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 3rem;
}

.feature-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 300px;
  margin: 0 auto;
}

.feature-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border-radius: 50px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: all 0.3s ease;
}

.feature-item:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: translateX(10px);
}

.feature-icon {
  font-size: 1.5rem;
}

/* 右侧表单区域 */
.form-section {
  animation-delay: 0.4s;
}

.login-card {
  padding: 3rem !important;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.form-header {
  text-align: center;
  margin-bottom: 2.5rem;
}

.form-title {
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(135deg, #ec4899, #d946ef, #8b5cf6);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.5rem;
}

.form-subtitle {
  color: #64748b;
  font-size: 0.95rem;
}

.login-form {
  margin-top: 2rem;
}

.login-form :deep(.el-form-item) {
  margin-bottom: 1.5rem;
}

.input-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  color: #475569;
  font-weight: 500;
  font-size: 0.9rem;
}

.login-button {
  width: 100%;
  height: 48px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 12px;
  margin-top: 0.5rem;
}

.form-footer {
  text-align: center;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid #e2e8f0;
}

.footer-text {
  color: #64748b;
  font-size: 0.9rem;
}

.register-link {
  font-weight: 600;
  font-size: 0.9rem;
  margin-left: 0.5rem;
}

.register-link:hover {
  background: linear-gradient(135deg, #ec4899, #d946ef);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .login-content {
    grid-template-columns: 1fr;
    padding: 2rem;
  }
  
  .brand-section {
    display: none;
  }
  
  .form-section {
    max-width: 500px;
    margin: 0 auto;
  }
}

/* 手机端优化 - 移动优先 */
@media (max-width: 640px) {
  .login-container {
    background: linear-gradient(135deg, #1e1b4b 0%, #581c87 100%);
  }
  
  .login-content {
    padding: 1rem;
    min-height: 100vh;
    display: flex;
    align-items: center;
  }
  
  .form-section {
    width: 100%;
  }
  
  .login-card {
    padding: 1.5rem !important;
    border-radius: 20px;
  }
  
  .form-header {
    margin-bottom: 2rem;
  }
  
  .form-title {
    font-size: 1.75rem;
  }
  
  .form-subtitle {
    font-size: 0.875rem;
  }
  
  .login-form :deep(.el-form-item) {
    margin-bottom: 1.25rem;
  }
  
  .input-label {
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
  }
  
  .login-button {
    height: 50px;
    font-size: 1rem;
    border-radius: 12px;
  }
  
  .form-footer {
    margin-top: 1.25rem;
    padding-top: 1.25rem;
  }
  
  .footer-text,
  .register-link {
    font-size: 0.875rem;
  }
  
  /* 优化输入框大小 */
  .login-form :deep(.el-input__wrapper) {
    padding: 12px 15px;
  }
  
  .login-form :deep(.el-input__inner) {
    font-size: 16px; /* 防止iOS自动缩放 */
  }
}

/* 超小屏幕优化 */
@media (max-width: 375px) {
  .login-card {
    padding: 1.25rem !important;
  }
  
  .form-title {
    font-size: 1.5rem;
  }
  
  .login-button {
    height: 48px;
    font-size: 0.95rem;
  }
}
</style>

